{extend name="platform/base" /}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 验证码设置 </header>
	<div class="panel-body">
		<form class="form-horizontal" id="wpay_form"  method="post">
			<div class="form-group">
				<label class="col-sm-2 control-label">平台验证码是否开启</label>
				<div class="col-md-4">
					<label class="switch">
						<input type="checkbox" id="platformCode" {if condition="$code_config.platform eq 1"}checked{/if}>
						<span></span>
					</label>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">后台验证码是否开启</label>
				<div class="col-md-4">
					<label class="switch">
						<input type="checkbox" id="adminCode" {if condition="$code_config.admin eq 1"}checked{/if}>
						<span></span>
					</label>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">商城验证码是否开启</label>
				<div class="col-md-4">
					<label class="switch">
						<input type="checkbox" id="pcCode" {if condition="$code_config.pc eq 1"}checked{/if}>
						<span></span>
					</label>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<button type="submit" class="btn btn-primary" onclick="setCodeConfigAjax()">保存</button>
				</div>
			</div>
		</form>
	</div>
</section>

<script>	
	function setCodeConfigAjax(){
		$('.btn').attr('disabled',true);
		if($("#platformCode").prop("checked")){
			var platformCode = 1;
		}else{
			var platformCode = 0;
		}
		if($("#adminCode").prop("checked")){
			var adminCode = 1;
		}else{
			var adminCode = 0;
		}
		if($("#pcCode").prop("checked")){
			var pcCode = 1;
		}else{
			var pcCode = 0;
		}
		$.ajax({
			type:"post",
			url:"{:__URL('PLATFORM_MAIN/config/codeconfig')}",
			data:{
				'platform' : platformCode,
				'adminCode' : adminCode,
				'pcCode' : pcCode
			},
			async:true,
			success:function (data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/config/codeconfig')}");
				}else{
					showMessage('error', data["message"]);
				}	
			}
		});
	}
</script>
{/block}